package org.getOffer.offer17;

/**
 * @Author: wjy
 * @Date: 2021/12/1 16:34
 */
public class Solution {

    public static void main(String[] args) {

        Solution solution = new Solution();
        String s = solution.printNumbers(2);

        char[] test = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

        System.out.println(s);

    }

    StringBuilder res;
    int nine = 0, count = 0, start, n;
    char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
/*    public String printNumbers(int n) {
        this.n = n;
        res = new StringBuilder();
        num = new char[n];
        start = n - 1;
        dfs(0);
        res.deleteCharAt(res.length() - 1);
        return res.toString();
    }
    void dfs(int x) {
        if(x == n) {
            String s = String.valueOf(num).substring(start);
            if(!s.equals("0")) res.append(s + ",");
            if(n - start == nine) start--;
            return;
        }
        for(char i : loop) {
            if(i == '9') nine++;
            num[x] = i;
            dfs(x + 1);
        }
        nine--;
    }*/

    public String printNumbers(int n) {
        this.n = n;
        res = new StringBuilder();
        num = new char[n];
        start = n - 1;
        this.dfs(0);
        return res.deleteCharAt(res.length() - 1).toString();

    }

    public void dfs(int x) {

        if (x == 2) {
            if (String.valueOf(num).substring(start) != "0") {
                res.append(String.valueOf(num).substring(start) + ",");
            }
            if (n - start == nine) {
                start--;
            }
            return;

        } else {
            for (char c : loop) {
                if (c == '9') {
                    nine++;
                }
                num[x] = c;
                dfs(x + 1);
            }
            nine--;
        }

    }

}
